Page History: Markets
Compare Page Revisions
Page Revision: 2012/01/23 10:50
The Markets property on the MarketData object contains all the markets that have been loaded. It does not contain all the available markets.
The Market object provides the details of a single market, and allows quotes to be obtained. The properties and methods are described
here.
To obtain quotes for a market you must subscribe to it using the
DepthSubscribe method:
' Subscribe to the market.
oMarket.DepthSubscribe(DepthBuffer.Smart, DepthLevels.Normal)
The parameters are as follows:
Buffer | The buffering that should be applied. Smart is the default and is the recommended buffering setting: DepthBuffer |
Levels | The amount of depth that is required. Normal is the default and provides 10 lines of depth: DepthLevels |
In order to maintain the correct subscription level then you must handle the
MarketCheckSubscription event. If you unsubscribe from a market, or if the API itself changes the subscription level when calculating P&L, then the market will raise a MarketCheckSubscription event to check to see if there is anything else in your application that still needs the subscription. An example of how to handle this event is shown below:
' Ensure that we remain subscribed.
Private Sub moMarket_MarketCheckSubscription(ByVal poMarket As Market, ByRef penDepthBuffer As DepthBuffer, ByRef penDepthLevels As DepthLevels) Handles moMarket.MarketCheckSubscription
penDepthBuffer = poMarket.DepthSubscribeAtLeast(DepthBuffer.Smart, penDepthBuffer)
penDepthLevels = poMarket.DepthSubscribeAtLeast(DepthLevels.All, penDepthLevels)
End Sub
All the handler needs to do is to set the DepthBuffer and DepthLevels parameters to the minimum setting you need, or to the setting passed. You can use the
DepthSubscribeAtLeast method to achieve this by passing the level you need and the level passed and it will return the highest of the two values.
NOTE: if you do not implement this event handler correctly then your market subscriptions will stop whenever your position becomes flat.This allows you to use the same market in several places in your application and have each place take care of its own subscription. Then when the market subscription is no longer needed by any part of your application the API will automatically unsubscribe.
When new market data is received then events are raised. These events are raised directly from the Market object itself, from MarketList objects that the market is contained in and from the MarketData object as well. Which is best for you use to pick up the events depends on how you are structuring your application.
Changes to the depth of market (the bids and offers) and last trade details are raised in the
MarketDepthUpdate event. The changes have been applied to the Market’s LastDepth property.
' Event raised when there is a new depth update for the market.
Private Sub moFilter_MarketDepthUpdate(ByVal poMarket As T4.API.Market) Handles moFilter.MarketDepthUpdate
' Display the trade volume changes.
Dim sText As String
sText = "DepthUpdate: " & poMarket.Description
' Display some of the depth details.
sText = sText & ", LastTrade: " & _
poMarket.LastDepth.LastTradeVolume & "@" & _
poMarket.ConvertTicksDisplay( _
poMarket.LastDepth.LastTradeTicks)
' Display the data.
Trace.WriteLine(sText)
End Sub